import sys
from PyQt6.QtWidgets import (QWidget, QGridLayout, QPushButton, QLabel, QLineEdit,QTextEdit,QApplication, QVBoxLayout)
from qfluentwidgets import BodyLabel, CardWidget


class Example(CardWidget):

    def __init__(self):
        super().__init__()

        self.initUI()


    def initUI(self):
        vbox = QVBoxLayout()

        # QGridLayout 实例创建了并把布局设置到窗口中。
        grid = QGridLayout()

        # 要用到的按钮上的标签。
        names = ['金', '木', '水', '火',
                 '土', '东', '西', '南',
                 '北', '中', '仁', '义',
                 '理', '智', '信', '忠',
                 '孝', '风', '水', '易']

        positions = [(i, j) for i in range(5) for j in range(4)]

        for position, name in zip(positions, names):

            if name == '':
                continue

            button = BodyLabel(name)
            button.setStyleSheet("background-color: lightblue;")
            # 创建了按钮，并用 addWidget 方法添加到布局里。
            grid.addWidget(button, *position)

        title = QLabel('姓名')
        author = QLabel('作者')
        review = QLabel('评论')

        titleEdit = QLineEdit()
        authorEdit = QLineEdit()
        reviewEdit = QTextEdit()

        # 创建一个格栅布局，并设置了组件间的分割空间。
        grid2 = QGridLayout()
        grid2.setSpacing(10)

        grid2.addWidget(title, 1, 0)
        grid2.addWidget(titleEdit, 1, 1)

        grid2.addWidget(author, 2, 0)
        grid2.addWidget(authorEdit, 2, 1)

        grid2.addWidget(review, 3, 0)
        # 如果需要往格栅里添加组件，指定组件的跨行和跨列的个数。本例，reviewEdit 组件占用了 5 行。
        grid2.addWidget(reviewEdit, 3, 1, 5, 1)


        vbox.addLayout(grid)
        # vbox.addLayout(grid2)
        self.setLayout(vbox)

        # self.move(300, 150)
        self.setWindowTitle('中国文化')
        self.show()


def main():

    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec())


if __name__ == '__main__':
    main()